package cn.iune.erp.customer;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Aspect//指定这是一个其切面
public class FileCustomerDaoAspect {
	
	@Autowired
	private IFileCustomerService fileCustomerService;

	
	//指定切入点（增加）
    @Pointcut("execution(* cn.iune.erp.customer.IFileCustomerDao.insert(..)) && args(obj)")
    public void insertPointCut(FileCustomer obj){}
    //指定通知以及通知的范围
    @Transactional
    @After("insertPointCut(obj)")
    public void beforeInsert(FileCustomer obj){
    	fileCustomerService.beforeInsert(obj);
    }
    
    @Transactional
    @After("insertPointCut(obj)")
    public void afterInsert(FileCustomer obj){
    	fileCustomerService.afterInsert(obj);
    }
    
	//指定切入点（删除）
    @Pointcut("execution(* cn.iune.erp.customer.IFileCustomerDao.delete(..)) && args(fID)")
    public void deletePointCut(String fID){}
    //指定通知以及通知的范围
    @Transactional
    @Before("deletePointCut(fID)")
    public void beforeDelete(String fID){
    	fileCustomerService.beforeDelete(fID);
    }
    
	//指定切入点（修改）
    @Pointcut("execution(* cn.iune.erp.customer.IFileCustomerDao.update(..)) && args(obj)")
   public void updatePointCut(FileCustomer obj){}
    //指定通知以及通知的范围
    @Transactional
    @Around("updatePointCut(obj)")
     public FileCustomer aroundUpdate(JoinPoint joinPoint, FileCustomer obj) throws Throwable{
         System.out.println("FileCustomerDaoAspect环绕通知上。。。");
         fileCustomerService.beforeDelete(obj.getfID());
         FileCustomer objNew = (FileCustomer) ((ProceedingJoinPoint) joinPoint).proceed();
         System.out.println("FileCustomerDaoAspect环绕通知下。。。");
         fileCustomerService.afterInsert(obj);
         return objNew;
     }


}
